# 创建
print('==============创建==============')
ls = []
a = ['aa','bb']
b = (11,22)
ls = [1,2,3,4,5,33,23,11,45]

# 末尾增一个元素
print("===========增====================")
res = ls.append(8)
print(res) # 无返回值
print(ls)

# 末尾批量增加
res1 = ls.extend(a)
print(res1)
print(ls)

res2 = ls.extend(b)
print(ls)

res3 = ls.extend({'c','d'})
print(ls)

res4 = ls.extend({'tom':18,'lucy':25})
print(ls)  # 把字典的键追加到列表末尾

res6 = range(6)
res5 = ls.extend(range(6))
print(ls)

# 指定位置增加元素
ls.insert(0,'dd')
print(ls)

# 使用运算符增加
res7 = ls + ['e','f']
print(res7)

res8 = a*3
print(res8)

# 成员判端
print("===============成员判断==============")
res9 = 11 in ls
print(res9)
res10 = 's' not in ls
print(res10)

# 改
print("==========改============")
print('a------>',a)
a[1] = 999
print('a------>',a)

# 查
print('================查===============')
print(ls)
res12 = ls[3]
print(res12)

res13 = ls.index('lucy')
print(res13)


res14 = ls.index(1)
print(res14) # 返回第一个匹配项

#res16 = ls.index('gggg')
#print(res16) # 匹配元素找不到ValueError: 'gggg' is not in list

res15 = ls.count(3) # 统计元素2出现个数
print(res15)

# 删
print('==============删===============')
print('ls------------->remove',ls)
res16 = ls.remove(1) # 从左往右匹配，删除第一个为1的元素
print(res16)
print('ls------------->',ls)

print('ls------------->pop()',ls)
res16 = ls.pop()
print(res16)
print('ls------------->',ls)

print('ls------------->pop(index)',ls)
res16 = ls.pop(3)
print(res16)
print('ls------------->',ls)

print('ls------------->del ls(index)',ls)
del ls[2]
print('ls------------->',ls)

print('ls------------->del ls',ls)
del ls
# print('ls------------->',ls) # NameError: name 'ls' is not defined

# 内置方法
print("===============内置方法=============")
c = [1,34,23,15,16,45]
print("=========len==============")
print(len(c)) # 返回列表长度

print('========max===========')
print(max(c))

ls1 = [{'a':3,'b':4},{'a':12,'b':12},{'a':23,'b':16},{'a':8,'b':21}]
print('============max+lambda===============')
res21 = max(ls1,key=lambda x: x['a'])
print(res21)
print('=========min==========')
print(min(c))

print("===========sort==========")
print(c.sort())
print(c)


print("==========reverse=========")
print(c.reverse())
print(c)


# 列表元素访问，索引切片
print('======元素访问、切片============')
d = ['a','b','c','d','e','f','g','h']
res17 = d[2]
print(res17)

res18 = d[-1]
print(res18)

res19 = d[1::3]
print(res19)

